package com.android.phoenix.activity.location;

import java.util.ArrayList;

import com.android.phoenix.R;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class SportNaviDetailActivity extends Activity {
	private ArrayList<String> listNodesDec = new ArrayList<String>();
	private ImageView title_Imgbtn_left_up;
	private TextView title_txt_center;
	private TextView title_txt_right_up;
	private ListView list_details;

	private naviDetailsAdapter adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acti_sport_navidetails);

		Bundle bundle = getIntent().getExtras();
		listNodesDec = bundle.getStringArrayList("nodes");
		initView();

	}

	private void initView() {
		initTitleBar();
		list_details = (ListView) this.findViewById(R.id.list_details);
		adapter = new naviDetailsAdapter(SportNaviDetailActivity.this,
				listNodesDec);
		list_details.setAdapter(adapter);
	}

	private void initTitleBar() {
		title_Imgbtn_left_up = (ImageView) this
				.findViewById(R.id.title_Imgbtn_left_up);
		title_Imgbtn_left_up.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		title_txt_center = (TextView) this.findViewById(R.id.title_txt_center);
		title_txt_center.setText(R.string.label_sport_navi_details);

		title_txt_right_up = (TextView) this
				.findViewById(R.id.title_txt_right_up);
		title_txt_right_up.setVisibility(View.GONE);
	}

	class ViewHolder {
		ImageView img_list_item;
		TextView txt_list_item;
	}

	private class naviDetailsAdapter extends BaseAdapter {
		LayoutInflater layoutInflater;
		Context context;
		ViewHolder viewHolder = null;
		ArrayList<String> naviDeatlsListStr = new ArrayList<String>();

		public naviDetailsAdapter(Context context,
				ArrayList<String> naviDeatlsListStr) {
			this.context = context;
			this.naviDeatlsListStr = naviDeatlsListStr;
			layoutInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return naviDeatlsListStr.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return naviDeatlsListStr.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View view, ViewGroup viewGroup) {
			// TODO Auto-generated method stub
			if (view == null) {
				viewHolder = new ViewHolder();
				view = layoutInflater.inflate(
						R.layout.list_item_sport_navidetails, null);
				viewHolder.txt_list_item = (TextView) view
						.findViewById(R.id.txt_details);
				viewHolder.img_list_item = (ImageView) view
						.findViewById(R.id.img_direction);
				view.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) view.getTag();
			}
			viewHolder.txt_list_item.setText(Html.fromHtml(naviDeatlsListStr
					.get(position)));
			if (naviDeatlsListStr.get(position).contains("起始")) {
				viewHolder.img_list_item
						.setImageResource(R.drawable.img_detail_start);
			} else if (naviDeatlsListStr.get(position).contains("左")) {
				viewHolder.img_list_item
						.setImageResource(R.drawable.img_detail_left);
			} else if (naviDeatlsListStr.get(position).contains("右")) {
				viewHolder.img_list_item
						.setImageResource(R.drawable.img_detail_right);
			} else if (naviDeatlsListStr.get(position).contains("掉头")
					|| naviDeatlsListStr.get(position).contains("环岛")) {
				viewHolder.img_list_item
						.setImageResource(R.drawable.img_detail_back);
			} else if (naviDeatlsListStr.get(position).contains("终点")) {
				viewHolder.img_list_item
						.setImageResource(R.drawable.img_detail_end);
			}
			return view;
		}
	}
}
